/** @file usb.h
  *
  * @brief This file contains the usb device definitions and oal func
  * for usb.
  *
  *  Copyright (C) 2024, Artosyn Technologies. ALL RIGHTS RESERVED.
  *
  *  This Information is proprietary to Artosyn Technologies and MAY NOT
  *  be copied by any method or incorporated into another program without
  *  the express written consent of Artosyn. This Information or any portion
  *  thereof remains the property of Artosyn. The Information contained herein
  *  is believed to be accurate and Artosyn assumes no responsibility or
  *  liability for its use in any way and conveys no license or title under
  *  any patent or copyright and makes no representation or warranty that this
  *  Information is free from patent or copyright infringement.
  *
***/

#ifndef _USB_H
#define _USB_H

/** Whether enable the power management  */
#define AR_BUS_PM 1

/****************************
 * USB Firmware download
 ****************************/
/** Timeout of firmware download req */
#define USB_TIMEOUT           (60000)

/** Magic of USB firmware download req */
#define ARTO_USB_MAGIC_NUM_0        'U'
#define ARTO_USB_MAGIC_NUM_1        'S'

/** Payload size of ctrl EP */
#define ARTO_USB_EP0_MAX_PAYLOAD_SIZE (ARTO_USB_EP0_TRAN_SIZE - sizeof(struct artousb_cmd_header))

/** Define of USB firmware download done */
#define ARTO_USB_EXIT_LEN             (0x0)
#define ARTO_USB_EXIT_ADDR            (0x0)

/** Payload size of ctrl EP transfer size */
#define ARTO_USB_EP0_TRAN_SIZE      (0x1000)

/** CMD of USB firmware download */
#define ARTO_USB_DNLD_VENDOR_CMD    (0x0C)

#pragma pack(push)
#pragma pack(1)

/** Structure of USB firmware download */
struct artousb_cmd_header
{
    unsigned char   magic_head[2];
    unsigned short  len;
    unsigned long long dst_addr;
};
#pragma pack(pop)

/****************************
 * Function API definition
 ****************************/

/**
 * @brief This function dump the information of USB.
 *
 *  @param ar_dev  Refers to ar_udev.
 *
 *  @return        N/A.
 */
void ar_usb_dump_info(void *ar_dev);

/**
 * @brief Insmod the usb device.
 *
 *  @return        Linux err code.
 */
int usb_init(void);

/**
 * @brief Rmmod the usb device.
 *
 *  @return        N/A.
 */
void usb_exit(void);

/** usb autopm. TBD */
int ar_usb_autopm_get_interface(void *ar_dev);
void ar_usb_autopm_put_interface(void *ar_dev);
void ar_usb_disable_autosuspend(void *ar_dev);
void ar_usb_enable_autosuspend(void *ar_dev);

#if (AR_BUS_PM == 1)
void ar_usb_set_pm_status(void *ar_udev, bool flag);
void ar_usb_resume_wait_and_reset(void *ar_udev);
#endif
#endif /* _USB_H */
